package leetcode;

import java.util.LinkedList;

public class Code009_FindPeakElement {

    public static int findPeakElement(int[] nums){

        LinkedList<Integer> stack = new LinkedList<>();
        for(int i = 0; i < nums.length; i++){
            while(!stack.isEmpty() && nums[i] < nums[stack.peek()]){
                return stack.pop();
            }
            stack.push(i);
        }
        return nums.length - 1;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,1,3,5,6,4};
        int res = findPeakElement(nums);
        System.out.println(res);
        int[] nums2 = {1};
        int res2 = findPeakElement(nums2);
        System.out.println(res2);
    }
}
